package com.example.prison.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.AttendanceDeviceInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【attendance_device_info】的数据库操作Mapper
* @createDate 2023-04-19 11:30:58
* @Entity com.example.military.entity.AttendanceDeviceInfo
*/
@Mapper
public interface AttendanceDeviceInfoMapper extends BaseMapper<AttendanceDeviceInfo> {

//    @Select("select * from attendance_device_info order by device_id desc")
    @Select("<script>select * from attendance_device_info " +
            " <where> " +
            " <if test=\"deviceNumber != null and deviceNumber != ''\">and device_number like concat('%',#{deviceNumber},'%') </if> " +
            " <if test=\"deviceName != null and deviceName != ''\">and device_name like concat('%',#{deviceName},'%') </if> " +
            " </where> " +
            "order by device_id desc</script>")
    List<AttendanceDeviceInfo> get(@Param("deviceNumber")String deviceNumber, @Param("deviceName")String deviceName);

    @Insert("insert into attendance_device_info(device_name, device_number, device_area, is_use, device_status, access,type) " +
            "values (#{deviceName}, #{deviceNumber}, #{deviceArea}, #{isUse}, #{deviceStatus}, #{access}, #{type})")
    int add(AttendanceDeviceInfo attendanceDevice);

    @Delete("<script>delete from attendance_device_info where device_id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteAttendanceDevice(@Param("ids") Integer[] ids);

    @Delete("delete from attendance_device_info where device_number=#{deviceNumber}")
    void deleteByNumber(@Param("deviceNumber") String deviceNumber);

//    @Update("update attendance_device_info set device_name=#{attDevice.deviceName},device_number=#{attDevice.deviceNumber},
//    device_area=#{attDevice.deviceArea},is_use=#{attDevice.isUse},device_status=#{attDevice.deviceStatus},access=#{attDevice.access},
//    type=#{attDevice.type} where device_id = #{deviceId}")
    @Update({"<script> UPDATE attendance_device_info",
            "<set>",
            "<if test='attDevice.deviceName != null'>device_name = #{attDevice.deviceName},</if>",
            "<if test='attDevice.deviceNumber != null'>device_number = #{attDevice.deviceNumber},</if>",
            "<if test='attDevice.deviceArea != null'>device_area = #{attDevice.deviceArea},</if>",
            "<if test='attDevice.isUse != null'>is_use = #{attDevice.isUse},</if>",
            "<if test='attDevice.deviceStatus != null'>device_status = #{attDevice.deviceStatus},</if>",
            "<if test='attDevice.access != null'>access = #{attDevice.access},</if>",
            "<if test='attDevice.type != null'>type = #{attDevice.type},</if>",
            "</set>",
            "where device_id = #{deviceId} </script>"})
    int updateAttendanceDevice(AttendanceDeviceInfo attDevice,Integer deviceId);

    @Select("select * from attendance_device_info where device_id=#{deviceId}")
    AttendanceDeviceInfo getById(@Param("deviceId") Integer deviceId);

    @Select("select * from attendance_device_info where device_name like concat('%',#{deviceName},'%') order by device_id desc")
    List<AttendanceDeviceInfo> getByName(@Param("deviceName") String deviceName);

    @Select("select * from attendance_device_info where device_number like concat('%',#{deviceNumber},'%') order by device_id desc")
    List<AttendanceDeviceInfo> getByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from attendance_device_info where device_number =#{deviceNumber} order by device_id desc")
    List<AttendanceDeviceInfo> getListByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from attendance_device_info where device_number=#{deviceNumber} order by device_id desc")
    AttendanceDeviceInfo getOneByNumber(@Param("deviceNumber") String deviceNumber);

    @Select("select * from attendance_device_info where device_number=#{deviceNumber} and device_status=#{status} order by device_id desc")
    AttendanceDeviceInfo getOneByNumberAndStatus(@Param("deviceNumber") String deviceNumber,@Param("status") String status);

}




